package autoz.core.wizards;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExecutableExtension;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;

public abstract class AbstractNewProjectWizard  extends Wizard implements INewWizard, IExecutableExtension{
	
	// the model
	protected NewProjectModel model;
	
    // the perspective configuration element 
    protected IConfigurationElement configElement;
    
	// workbench selection when the wizard was started
	protected IStructuredSelection selection;
		
	// the workbench instance
	protected IWorkbench workbench;

	/**
	 * Constructor for NewProjectWizard.
	 */
	public AbstractNewProjectWizard() {
		super();
		model = new NewProjectModel();
	}

	/**
	 * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
	 */
	public void init(IWorkbench workbench, IStructuredSelection selection) 
	{
		this.workbench = workbench;
		this.selection = selection;
		if (selection != null && !selection.isEmpty()) {
//			Object obj = selection.getFirstElement();
			
			//TODO not sure what needs to go here.
		}
	}

	/**
	 * Display the finish button (or not).
	 */
	public abstract boolean canFinish();
	
	/**
	 * Action performed on clicking the finish button.
	 */
	public abstract boolean performFinish() ;
	
    /**
     * Handle the exceptions of project creation here.
     * @param target
     */
    protected abstract void handleTargetException(Throwable target);      

	public void setInitializationData(IConfigurationElement config,
			String propertyName, Object data) throws CoreException {
		configElement = config;
		
	}
}
